<template>
	<view>
		<view class="contner">
			<u-sticky>
				<u-tabs :list="tabsList" lineColor="#0E9698" :activeStyle="{
			  color: '#0E9698',
			}" :inactiveStyle="{
			  color: '#353535',
			}" :lineWidth="30" :current="currentTab" @click="onClickTab" />
			</u-sticky>
			<!-- "card_type":"time"   时间卡
			card type": "num"  次卡
			card type": "money "  充值卡 -->
			<template v-if="currentTab === 0">
				<view class="d-p-l-30 d-p-r-30" style="padding-left: 30rpx;padding-right: 30rpx;" v-if="list != ''">
					<view class="d-list-box d-m-t-20 d-p-20 d-flex d-col-top" v-for="(item, index) in list" 
						style="margin-top: 20rpx;" :key="index">
						<!-- <u-image :src="picture" width="148rpx" height="148rpx" shape="circle"></u-image> -->
						<view class="d-m-l-20 d-flex-1" style="margin-left: 20rpx;" v-if="item.open_state == 1"  @click="cardDetail(item)">
							<!-- <view class="d-white">场馆名称</view> -->
							<view class="d-cg">
								<view class="d-bold">{{item.venue_name}}</view>
								<view class="d-bold"  >
									<image :src="picture" mode="" style="width: 52rpx;height: 52rpx;">
									</image>
								</view>
							</view>
							<view class="d-ming">
								<text style="padding: 1rpx 5rpx;background-color: #fff;color: #0E9698;border-radius: 10rpx;" v-if="item.open_state == 1">开卡</text>
								<text style="padding: 1rpx 5rpx;background-color: #fff;color: #0E9698;border-radius: 10rpx;" v-if="item.open_state == 0">未开卡</text>
								{{item.card_name}}
							</view>
							<view class="d-white">{{item.qr_code}}</view>
							<view class="d-xuxian d-white"></view>
							<view class="d-red">
								<view class="d-bold" v-if="item.card_type == 'money'">剩余：{{item.recharge }}元</view>
								<view class="d-bold" v-if="item.card_type == 'num'">剩余：{{item.recharge }}次</view>
								<view class="d-bold">{{item.deadline}}</view>
							</view>
							<!-- <view class="d-flex d-m-t-18">
								<view class="d-tag d-flex">{{ item.specify }}</view>
							</view>
							<view class="d-font-24 d-be d-m-t-20">{{ item.tip }}</view>
							<view class="d-font-24 d-be d-m-t-20" style="margin-left: 47rpx;">{{ item.text }}</view> -->
						</view>
						<view class="d-m-l-20 d-flex-1" style="margin-left: 20rpx;" v-if="item.open_state == 0">
							<!-- <view class="d-white">场馆名称</view> -->
							<view class="d-cg">
								<view class="d-bold">{{item.venue_name}}</view>
								<view class="d-bold"  >
								</view>
							</view>
							<view class="d-ming">
								<text style="padding: 1rpx 5rpx;background-color: #fff;color: #0E9698;border-radius: 10rpx;" v-if="item.open_state == 0">未开卡</text>
								{{item.card_name}}
							</view>
							<view class="d-white">{{item.qr_code}}</view>
							<view class="d-xuxian d-white"></view>
							<view class="d-red">
								<view class="d-bold" v-if="item.card_type == 'money'">剩余：{{item.recharge }}元</view>
								<view class="d-bold" v-if="item.card_type == 'num'">剩余：{{item.recharge }}次</view>
								<view class="d-bold">{{item.deadline}}</view>
							</view>
						</view>
					</view>
				</view>
				<view  style="position: absolute;top: 0rpx; left: 30%;" v-else>
					<u-empty mode="list" text="暂无数据~"
						:icon="zanwu_img">
					</u-empty>
				</view>
			</template>
			<template v-if="currentTab === 1">
				<view class="d-p-l-30 d-p-r-30" style="padding-left: 30rpx;padding-right: 30rpx;" v-if="list != ''">
					<view class="d-list-box3 d-m-t-20 d-p-20 d-flex d-col-top" v-for="(item, index) in list"
						style="margin-top: 20rpx;" :key="index">
						<!-- <u-image :src="picture" width="148rpx" height="148rpx" shape="circle"></u-image> -->
						<view class="d-m-l-20 d-flex-1" style="margin-left: 20rpx;">
							<!-- <view class="d-white">场馆名称</view> -->
							<view class="d-cg">
								<view class="d-bold">{{item.venue_name}}</view>
								<view class="d-bold">
									<image :src="picture" mode="" style="width: 52rpx;height: 52rpx;">
									</image>
								</view>
							</view>
							<view class="d-ming">
								<!-- <text style="padding: 1rpx 5rpx;background-color: #fff;color: #0E9698;border-radius: 10rpx;" v-if="item.open_state == 1">开卡</text>
								<text style="padding: 1rpx 5rpx;background-color: #fff;color: #0E9698;border-radius: 10rpx;" v-if="item.open_state == 0">未开卡</text> -->
								{{item.card_name}}
							</view>
							<view class="d-white">{{item.qr_code}}</view>
							<view class="d-xuxian d-white"></view>
							<view class="d-red">
								<view class="d-bold" v-if="item.card_type == 'money'">剩余：{{item.recharge }}元</view>
								<view class="d-bold" v-if="item.card_type == 'num'">剩余：{{item.recharge }}次</view>
								<view class="d-bold">{{item.deadline}}</view>
							</view>
							<!-- <view class="d-flex d-m-t-18">
								<view class="d-tag d-flex">{{ item.specify }}</view>
							</view>
							<view class="d-font-24 d-be d-m-t-20">{{ item.tip }}</view>
							<view class="d-font-24 d-be d-m-t-20" style="margin-left: 47rpx;">{{ item.text }}</view> -->
			
						</view>
					</view>
				</view>
				<view  style="position: absolute;top: 0rpx; left: 30%;" v-else>
					<u-empty mode="list" text="暂无数据~"
						:icon="zanwu_img">
					</u-empty>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	const index = require("@/api/index/index.js");
	export default {
		data() {
			return {
				currentTab: 0,
				picture: this.$https.assetsPath + "20231120/714febf033f24564bd4620630796b87a.png",
				tabsList: [{
					name: "待使用"
				},
				{
					name: "已过期"
				}],
				listQuery: { //分页
					limit: 5,
					page: 1,
				},
				totalPage: "",
				list:[],
				zanwu_img: this.$https.assetsPath + "image22.png",
			};
		},
		onLoad(e) {
			this.cardlist()
		},
		methods: {
			async cardlist() {
				let that = this;
				if (this.listQuery.page === 1) that.list = [];
				
				let postData = {
					page: this.listQuery.page,
					limit: this.listQuery.limit,
					order:'desc',
					sort:'id',
				};
				let res = await index.user_card(postData);
				if (res.code === 1) {
					console.log(res.data,'222')
					this.list = this.list.concat(res.data.rows); //将数据拼接在一起
					that.totalPage = res.data.last_page
				}else if(res.code == -1){
					uni.showToast({
						title: res.msg,
						duration: 1000,
						icon: 'none'
					});
					setTimeout(()=>{
						wx.clearStorageSync()
						wx.clearStorage()
						uni.switchTab({
							url: '/pages/personal/personal', //跳去登录页
						})
					},2000) 
				}
			},
			async cardnolist() {
				let that = this;
				if (this.listQuery.page === 1) that.list = [];
				let postData = {
					page: this.listQuery.page,
					limit: this.listQuery.limit,
					order:'desc',
					sort:'id',
				};
				let res = await index.user_cardno(postData);
				if (res.code === 1) {
					this.list = this.list.concat(res.data.rows); //将数据拼接在一起
					console.log(this.list,'555')
					that.totalPage = res.data.last_page
				}
			},
			// 下拉刷新
			onReachBottom() {
				if (this.totalPage <= this.listQuery.page) {
					uni.showToast({
						title: '没有更多了',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				this.listQuery.page += 1;
				if (this.currentTab == 0) {
					this.cardlist()
				} else{
					this.cardnolist()
				}
			},
			onClickTab({
				index
			}) {
				this.currentTab = index;
				this.list = []
				this.listQuery.page = 1
				if (index == 0) {
					this.cardlist()
				} else {
					this.cardnolist()
				}
			},
			cardDetail(item){
				uni.navigateTo({
					url:'/pages_other/ewm_card/ewm_card?id=' + item.id
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.contner{
		/deep/.u-tabs {
			background-color: #fff;
			border-bottom: 1px solid #e5e5e5;
		
			.u-tabs__wrapper__nav__item {
				flex: 1;
			}
		
			.u-tabs__wrapper__nav__line {
				bottom: 0;
			}
		}
		.d-list-box {
			box-shadow: 0rpx 13rpx 57rpx 0rpx rgba(8, 73, 162, 0.11);
			background: rgb(48, 182, 134);
			border-radius: 10rpx;
		}
		
		.d-list-box1 {
			box-shadow: 0rpx 13rpx 57rpx 0rpx rgba(8, 73, 162, 0.11);
			background: #35bcff;
			border-radius: 10rpx;
		}
		
		.d-list-box2 {
			box-shadow: 0rpx 13rpx 57rpx 0rpx rgba(8, 73, 162, 0.11);
			background: rgb(253, 168, 92);
			border-radius: 10rpx;
		}
		.d-list-box3 {
			box-shadow: 0rpx 13rpx 57rpx 0rpx rgba(8, 73, 162, 0.11);
			background: rgb(194, 194, 194);
			border-radius: 10rpx;
		}
		
		.d-tag {
			background: #f3f3f3;
			border-radius: 4rpx;
			height: 36rpx;
			font-size: 24rpx;
			font-weight: 500;
			color: #333333;
			padding: 0 18rpx;
		}
		
		.d-be {
			color: #bebebe;
		}
		
		.d-red {
			color: #ffffff;
			margin-top: 20rpx !important;
			font-size: 30rpx;
			margin-bottom: 20rpx;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
		}
		
		.d-cg {
			color: #ffffff;
			margin-top: 20rpx !important;
			font-size: 30rpx;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
		}
		
		.d-ming {
			color: #ffffff;
			margin-top: 10rpx !important;
			font-size: 30rpx
		}
		
		.d-white {
			color: #ffffff;
			margin-top: 20rpx !important;
			font-size: 30rpx
		}
		
		.d-xuxian {
			width: 86vw;
			height: 1rpx;
			border-bottom: 1px dashed white;
			margin-top: 10rpx;
		}
		
		.d-bold {
			font-weight: bold;
			margin-right: 20rpx;
		}
	}
	
</style>